﻿@using Lib.core;
@using Lib.helper;
@using Model.Category;
@{
    Layout = null;
    HttpContext context = System.Web.HttpContext.Current;
}

<style type="text/css">
    .dropdown:hover > .dropdown-menu {
        display: block;
    }
</style>

<div id="nav_wrapper">
    <div class="navbar nav_cls white_nav" style="margin-bottom: 0;">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand logo-img" href="/page/home/" target="_self">@(web_name)</a>
            </div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

                <ul class="nav navbar-nav navbar-right hide_when_sm">
                    @if (this.X.User != null)
                    {
                        <li>
                            <a class="hover" href="/user/usercenter/" rel="nofollow" target="_self">
                                <span class="fa fa-user"></span>
                                <span>个人中心</span>
                            </a>
                        </li>
                        <li>
                            <a href="/account/login/?logout=1" rel="nofollow" target="_self">
                                <span class="fa fa-power-off"></span>
                                <span>退出</span>
                            </a>
                        </li>
                    }
                    else
                    {
                        <li>
                            <a class="hover" href="/account/loginaction/" rel="nofollow" target="_self">
                                <span class="fa fa-lock"></span>
                                <span>登陆</span>
                            </a>
                        </li>
                        <li>
                            <a href="/account/register/" rel="nofollow" target="_self">
                                <span class="fa fa-check"></span>
                                <span>注册</span>
                            </a>
                        </li>
                    }
                </ul>

                @{
                    IList<CategoryModel> list = ViewData["nav_list"] as IList<CategoryModel>;
                }

                @if (ValidateHelper.IsPlumpList(list))
                {
                    IList<CategoryModel> droplist = null;

                    <ul class="nav navbar-nav navbar-left">
                        @foreach (var model in list.Where(x => x.CategoryLevel == 0))
                        {
                            droplist = list.Where(
                                x => x.CategoryParent == model.UID
                                && x.CategoryLevel == model.CategoryLevel + 1).ToList();

                            <li class="@(ValidateHelper.IsPlumpList(droplist) ? "dropdown" : "no_dropdown")">
                                <a href="@(model.LinkURL)" target="@(model.OpenInNewWindow == "true" ? "_blank" : "_self")">
                                    @if (ValidateHelper.IsPlumpString(model.IconClass))
                                    {
                                        <span class="@(model.IconClass)"></span>
                                    }
                                    <span>@(model.CategoryName)</span>
                                </a>
                                @if (ValidateHelper.IsPlumpList(droplist))
                                {
                                <!--下拉开始-->
                                    <ul class="dropdown-menu">
                                        @foreach (var drop in droplist)
                                        {
                                            <li>
                                                <a href="@(drop.LinkURL)"
                                                   target="@(drop.OpenInNewWindow == "true" ? "_blank" : "_self")">
                                                    @(drop.CategoryName)
                                                </a>
                                            </li>
                                        }
                                    </ul>
                                <!--下拉结束-->
                                }
                            </li>
                        }
                    </ul>
                }

            </div>
        </div>
    </div>
</div>




<script type="text/javascript">
    $(function () {

        var nav_wapper = $('#nav_wrapper');
        var nav = $('.nav_cls');

        $(window).resize(function () {
            nav.addClass('navbar-fixed-top').addClass('z-depth-1');
            if ($('body').attr('data-navflow') != 'true') {
                nav_wapper.height(nav.height());
            }
        }).trigger('resize');

        //导航的自动显示和隐藏
        var prevScroll = 0;
        var curDir = 'down';
        var prevDir = 'up';
        $(window).scroll(function () {
            if ($(this).scrollTop() > prevScroll) {
                curDir = 'down';
                if (curDir != prevDir) {
                    nav.stop().animate({ top: -1 * nav.height() }, 'fast');
                    prevDir = curDir;
                }
            } else {
                curDir = 'up';
                if (curDir != prevDir) {
                    nav.stop().animate({ top: 0 }, 'fast');
                    prevDir = curDir;
                }
            }
            prevScroll = $(this).scrollTop();
        });

    });
</script>
